package cn.chinaflame.pagodas.web;

import java.sql.SQLException;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.chinaflame.pagodas.annotation.ApiDoc;
import cn.chinaflame.pagodas.dto.PaBlessDto;
import cn.chinaflame.pagodas.dto.PaLightsLogDto;
import cn.chinaflame.pagodas.entity.PaLightsLog;
import cn.chinaflame.pagodas.enums.CodeEnum;
import cn.chinaflame.pagodas.repository.PaLightsLogRepository;
import cn.chinaflame.pagodas.service.CommonService;
import cn.chinaflame.pagodas.service.IdGeneratorService;
import cn.chinaflame.pagodas.service.PaLightsLogService;
import cn.chinaflame.pagodas.utils.ParamPreconditions;
import cn.chinaflame.pagodas.utils.stl.DateUtil;
import cn.chinaflame.pagodas.utils.stl.DateUtils;

 /**
  * 记录寻灯，安灯，检查灯位，清灯操作日志
  * @author pengcheng.zhao
  *
  */
@RestController
@Transactional(rollbackFor = Exception.class)
@RequestMapping(value = "/openapi/v1/pagodas/lightslog/")
public class PaLightsLogAPI{
	
	    private static final Logger log = LoggerFactory.getLogger(PaLightsLogAPI.class);

	    @Autowired
	    private JdbcTemplate jdbcTemplate;
	    @Autowired
	    private PaLightsLogService paLightsLogService;
	    @Autowired
	    private CommonService commonService;
	    @Autowired
	    private IdGeneratorService idGeneratorService;
	    
	    
	/**
	 * 通过日期查询
	 * @param date
	 * @return
	 */
	@GetMapping(value="findByCreatetime")
	@ApiDoc(PaLightsLogDto.class)
    public List<PaLightsLog> findByCreatetime(String date) {
//		ParamPreconditions.checkDateByFmt(date, DateUtil.SIMPLE_DATE_FROMAT);
		log.info("findByCreatetime:date:{}",date);
		List<PaLightsLog> lightlogs = paLightsLogService.findByCreatetime(date);
		log.info("lightlogs.size():{}",lightlogs !=null ? lightlogs.size():null);
    	return lightlogs;
    }
    
    /**
     * 通过灯号查询
     * @param lightno
     * @return
     */
	@GetMapping(value="findByLightno")
	@ApiDoc(PaLightsLogDto.class)
    public List<PaLightsLog> findByLightno(String lightno) {
		log.info("findByLightno:lightno:{}",lightno);
		List<PaLightsLog> lightlogs = paLightsLogService.findByLightno(lightno);
		log.info("lightlogs.size():{}",lightlogs !=null ? lightlogs.size():null);
    	return lightlogs;
    }
    
    /**
     * 通过消息查询
     * @param msg
     * @return
     */
	@GetMapping(value="findByMessage")
	@ApiDoc(PaLightsLogDto.class)
    public List<PaLightsLog> findByMessage(String msg) {
		log.info("findByMessage:msg:{}",msg);
		List<PaLightsLog> lightlogs = paLightsLogService.findByLightno(msg);
		log.info("lightlogs.size():{}",lightlogs !=null ? lightlogs.size():null);
    	return lightlogs;
    }
}
